package cc.verywell.pureblock.msg.nfs.linkmap;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import cc.verywell.pureblock.util.AutoClosed;

/**
* 
* Copyright © 2019 TanYaqiu. All rights reserved.
* @author TanYaqiu 
* @address flat 601
* @date 2019年6月19日 下午2:54:40
*/
public class EasyTablesUnsort implements EasyTables {

	final AutoClosed ac;
	final List<EasyTableHDhead> files;
	public EasyTablesUnsort(AutoClosed ac,List<EasyTableHDhead> readOnlyFiles) {
		this.ac = ac;
		this.files = readOnlyFiles;
	}
	
	@Override
	public EasyIteratorGroup get(EasyIteratorGroup group, LinkCell startWith) {
//		int a = 0,b = files.size()-1;
//		while(a<b) {
//			int c = (a+b)>>1;
//			int h = files.get(c).between(startWith);
//			if(h<0)a = c+1;
//			else b = c;
//		}
//		EasyTableHDhead h;
//		while((h=files.get(a)).between(startWith)==0) {
//			EasyIterator it = h.getTable(ac).get(startWith);
//			if(it!=null) {
//				if(group==null)group = new 	EasyIteratorGroup();
//				group.add(it);
//			}
//			if(++a>=files.size())
//				break;
//		}
		//好像只有4个文件吧;
		for (EasyTableHDhead h : files) {
			int i = h.startBetween(startWith);
			if(i==0) {
				EasyIterator it = h.getTable(ac).get(startWith);
				if(it!=null) {
					if(group==null)group = new 	EasyIteratorGroup();
					group.add(it);
				}
			}else if(i>0)
				break;
		}
		return group;
	}
}
